package erfgame.frontend.desktop.view.terrain.iso.interaction;

import erfgame.core.Point3D;
import erfgame.core.entity.Entity;
import erfgame.core.graphics.renderer.chain.EntityRendererChainFactory;
import erfgame.core.graphics.renderer.chain.RendererChain;

import erfgame.frontend.desktop.view.terrain.iso.EntitySelection;
import erfgame.frontend.desktop.view.terrain.iso.IsometricTerrainView;
import erfgame.frontend.desktop.view.terrain.iso.handler.InteractionHandler;

public class SelectEntityInteractionFactory implements EntityInteractionFactory {

	private EntitySelection selection;
	private EntityRendererChainFactory rendererChainFactory;
	private IsometricTerrainView view;
	
	public SelectEntityInteractionFactory( IsometricTerrainView view, EntitySelection selection, EntityRendererChainFactory rendererChainFactory ) {
		this.selection = selection;
		this.view = view;
		this.rendererChainFactory = rendererChainFactory;
	}
	
	public Interaction createInteraction(final Entity entity, Point3D terrain) {
		return new Interaction() {

			public InteractionHandler activate() {
				selection.clear();
				if( entity != null ) {
					RendererChain chain;
					chain = rendererChainFactory.getRendererChain(view.getCurrentWorld(), entity, view.getCurrentRotation());
					selection.addRendererChain(chain, view.getCurrentRotation());
				}
				return null;
			}
		};
	}

}
